package weixin.idea.huodong.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import weixin.idea.huodong.entity.HAcodeEntity;
import weixin.idea.huodong.entity.HAcodeHMEntity;
import weixin.idea.huodong.service.HAcodeServiceI;

@Service("haCodeService")
@Transactional
public class HAcodeServiceImpl extends CommonServiceImpl implements HAcodeServiceI {

	@Override
	public HAcodeHMEntity findHAcodeHMEntity(String accountId, HAcodeEntity hacode) {
		if(hacode != null){
			DetachedCriteria detachedCriteria = DetachedCriteria.forClass(HAcodeHMEntity.class);
			detachedCriteria.add(Restrictions.eq("haid", hacode.getId()));
			detachedCriteria.add(Restrictions.eq("opendid", accountId));
			List<HAcodeHMEntity> hacodeHMList = this.findByDetached(detachedCriteria);
			if (hacodeHMList != null && hacodeHMList.size() > 0) {
				HAcodeHMEntity hm = hacodeHMList.get(0);
				return hm;
			}
		}
		return null;
	}

}
